package io.renren.modules.sys.service.impl;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.modules.sys.dao.DormFareDao;
import io.renren.modules.sys.entity.DormFareEntity;
import io.renren.modules.sys.service.DormFareService;


@Service("dormFareService")
public class DormFareServiceImpl extends ServiceImpl<DormFareDao, DormFareEntity> implements DormFareService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        QueryWrapper<DormFareEntity> wrapper = new QueryWrapper<>();
//        if(params.get("key")!=null && !params.get("key").equals("")){
//            wrapper.like("dorm_id", params.get("key"));
//        }
        if(params.get("dormId")!=null && !params.get("dormId").equals("")){
            wrapper.like("dorm_id", Integer.parseInt((String)params.get("dormId")));
        }
        IPage<DormFareEntity> page = this.page(
                new Query<DormFareEntity>().getPage(params),
                wrapper
        );

        return new PageUtils(page);
    }

    @Override
    public PageUtils queryPage01(Map<String, Object> params) {
        QueryWrapper<DormFareEntity> wrapper = new QueryWrapper<>();
        String key = (String)params.get("key");
        wrapper.like(StringUtils.isNotBlank(key), "month",key);

        if (params.get("dormId")!=null){
            wrapper.eq("dorm_id", params.get("dormId"));
        }
        IPage<DormFareEntity> page = this.page(
                new Query<DormFareEntity>().getPage(params),
                wrapper
        );

        return new PageUtils(page);
    }

}